<?php

//$pic_goods = I("post.pic_goods");
//
//if ($pic_goods) {
//    $dir = C("uploads.upload") . "goods";
//    checkDirExists(C("uploads.upload") . "goods");
//    $logo_old = getSingleField($id, "goods", "logo");
//    unlink($logo_old);
//    $old = C("uploads.temp") . basename($pic_goods);
//    $new = $dir . "/" . basename($pic_goods);
//    rename($old, $new);
//    $data['logo'] = $new;
//}
$pics = I("post.pics");
$picsNew = array();

if($pics){
    $dir = C("uploads.upload") . "goods_pics/".getFileBei($id);
    checkDirExists($dir);
    foreach($pics as $v){
        if(!file_exists($v)){
            $old = C("uploads.temp") . basename($v);
            $new = $dir.basename($v);
            $v = $new;
             rename($old, $new);
        }
        $picsNew[] = $v;
    }
    
}
$info = M("goods_details")->field("pics")->where("goods_id = ".$id."")->find();
    
    $pics_old = json_decode($info['pics'],true);

    if($pics_old){
        foreach($pics_old as $v){
            if(!in_array($v,$picsNew)){
         delPics($v,array("800_800","120_120"));
            }
        }
    }
 
    
$data['logo'] = $pics?$picsNew[0]:"";
$data['logo2'] = $pics?$picsNew[1]:"";
$data_details['pics'] = $pics?json_encode($picsNew):"";
$sku_pic = I("post.sku_pic");
$sku_upload_ids = I("post.sku_upload_ids");
$sku_upload_names = I("post.sku_upload_names");
if ($sku_pic) {
    $dir = C("uploads.upload") . "sku_pic";
    checkDirExists(C("uploads.upload") . "sku_pic");
    foreach ($sku_pic as $k => $v) {
        if (strstr($v, $dir)) {
            $new = $v;
        } else {
            $old = C("uploads.temp") . basename($v);
            $new = $dir . "/" . basename($v);
        }

        $sku_pic[$k] = $new;
        rename($old, $new);
    }
}
$sku_pic_arr = array();
foreach ($sku_upload_ids as $k => $v) {
    $sku_pic_arr[$k]['id'] = $v;
    $sku_pic_arr[$k]['pic'] = $sku_pic[$k];
    $sku_pic_arr[$k]['name'] = $sku_upload_names[$k];
}
$data_details['sku_upload_pic'] = json_encode($sku_pic_arr);

?>
